﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Protal.Models;
using FluentValidation;
using Microhard.Protal.Resource;

namespace Microhard.Protal.Validators
{
    public class ArticleModelValidator : AbstractValidator<ArticleModel>
    {
        public ArticleModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.Title).NotEmpty().WithMessage(Msg.NeedTitle).When(c => c.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.Title).Length(1, 50).WithMessage(Msg.MaxTitle).When(c => c.OperationStatus == Core.DBUtility.OperationStatus.Add);

                RuleFor(u => u.Description).NotEmpty().WithMessage(Msg.NeedDescription).When(c => c.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.Description).Length(1, 200).WithMessage(Msg.MaxDescription).When(c => c.OperationStatus == Core.DBUtility.OperationStatus.Add);

                RuleFor(u => u.ArticleContent).NotEmpty().WithMessage(Msg.NeedArticleContent).When(c => c.OperationStatus == Core.DBUtility.OperationStatus.Add);
            });

            RuleSet("Update", () =>
            {
                RuleFor(u => u.Title).NotEmpty().WithMessage(Msg.NeedTitle);
                RuleFor(u => u.Title).Length(1, 50).WithMessage(Msg.MaxTitle);

                RuleFor(u => u.Description).NotEmpty().WithMessage(Msg.NeedDescription);
                RuleFor(u => u.Description).Length(1, 200).WithMessage(Msg.MaxDescription);

                RuleFor(u => u.ArticleContent).NotEmpty().WithMessage(Msg.NeedArticleContent);
            });
        }
    }
}
